package com.acme;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PlayerListAdapter extends ArrayAdapter<Player> {
	
	public PlayerListAdapter(Context context, int textViewResourceId, Player[] players) {
		super(context, textViewResourceId, players);
		Log.i("PlayerListAdapter", "Constructor");
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                //v = vi.inflate(R.layout.player_list_item, null);
                v = vi.inflate(R.layout.player_list_item, parent, false);
            }
            
            Player p = getItem(position);
            if (p != null) {
    				Log.i("PlayerListAdapter", "player: "+p);
                    TextView status = (TextView) v.findViewById(R.id.status);
                    TextView name = (TextView) v.findViewById(R.id.name);
                    TextView player_position = (TextView) v.findViewById(R.id.position);
                    TextView team = (TextView) v.findViewById(R.id.team);
                    TextView school = (TextView) v.findViewById(R.id.school);
                    if (status != null) {
                          status.setText(p.getStatusString());
                    }
                    if(name != null){
                          name.setText(p.getName());
                    }
                    if(player_position != null){
                    	player_position.setText(p.getPosition().toString());
                    }
                    if(team != null){
                    	team.setText(p.getTeam());
                    }
                    if(school != null){
                    	school.setText(p.getSchool());
                    }
            }
            return v;
    }
	
}
